//
//  QZEditNickNameVC.m
//  WeiWeiHaircut
//
//  Created by 上官惠阳 on 15/12/10.
//  Copyright © 2015年 超群. All rights reserved.
//

#import "QZEditNickNameVC.h"
#import "QZEditUserMsgCell.h"
#import "QZKeepView.h"

@interface QZEditNickNameVC ()

@end

@implementation QZEditNickNameVC
{
    UIView *_grayView;
    QZKeepView *_keepView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self titleWithSting:@"昵称"];
    [self addBtnOnNavWithTitle:@"取消" andImageName:@"返回" andTarget:self andAction:@selector(backAction) andFrame:CGRectMake(0, 0, 45, 20) andDirection:left];
    
    [self addBtnOnNavWithTitle:@"保存" andImageName:nil andTarget:self andAction:@selector(keepAction) andFrame:CGRectMake(0, 0, 40, 20) andDirection:right];
    
    [self createTableViewWithPlainStyle:YES andSeparatorStyleNone:YES andBackGroudImageName:nil];
    self.tableView.backgroundColor = BACKGROUDCOLOR;
    
    [self registCellWithNib:@"QZEditUserMsgCell" addIdentifier:@"editCell" addHeight:60];
    [self.tableSource addObject:@""];
    
    [self.tableView reloadData];
    
    [self addTap];
    
    [self createGrayView];
    [self createKeepView];
}
-(void)loadCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    QZEditUserMsgCell *editCell = (QZEditUserMsgCell *)cell;
    editCell.alertLabel.text = @"输入您的昵称...";
    self.seleteTextView  = editCell.contentTextView;
}
-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)createGrayView
{
    UIView *grayView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    grayView.backgroundColor = [UIColor blackColor];
    grayView.alpha = 0.5;
    grayView.hidden = YES;
    [self.view addSubview:grayView];
    _grayView = grayView;
}
-(void)createKeepView
{
    _keepView = [[[NSBundle mainBundle]loadNibNamed:@"QZKeepView" owner:self options:nil]lastObject];
    _keepView.frame = CGRectMake(0, 115 + 64, WIDTH, 125);
    _keepView.hidden = YES;
    [self.view addSubview:_keepView];
}
-(void)keepAction
{
    [self requestWithKeys:@[@"nick_name",@"user_id"] andValues:@[self.seleteTextView.text,[QZUserInfo userId]] andUrlKey:@"User.GetSetNkname" isCache:NO];
}
-(void)request_POST_FinishValue :(id)value tagNSString:(NSString *)tag
{
    NSLog(@"value = %@",value);

    if ([value[@"data"][@"status"] intValue] == 100) {
        _grayView.hidden = NO;
        _keepView.hidden = NO;
        
        [[TMCache sharedCache] setObject:self.seleteTextView.text forKey:@"nickName"];
        [self performSelector:@selector(backAction) withObject:nil afterDelay:0.7];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
